{extend name="base:base-add" /}
{block name="style"}
{/block}
{block name="title"}
<title>编辑下载文件地址</title>
{/block}
{block name="form"}
<div class="panel mt-20">
    <div class="panel-body">
        <div class="clearfix">
            <span class="f-r">共有数据：<strong>{$count}</strong> 条</span>
        </div>
        <div class="mt-20 clearfix">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr>
                    <th scope="col" colspan="4">下载列表</th>
                </tr>
                <tr class="text-c">
                    <th width="20">ID</th>
                    <th width="150">标题</th>
                    <th width="90">文件key</th>
                    <th width="50">操作</th>
                </tr>
                </thead>
                <tbody>
                {notempty name="files"}
                {volist name="files" id="vo"}
                <tr class="text-c">
                    <td>{$vo.id}</td>
                    <td class="text-l">{$vo.title}</td>
                    <td class="text-l">{$vo.aws_key}</td>
                    <td class="td-manage"><a title="编辑" href="javascript: void (0);"
                                             onclick="edit('{$vo.title}','/wavlink/files/download/edit/{$vo.id}.html')"
                                             class="ml-5"
                                             style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a
                            title="删除" href="javascript:void (0);" onclick="del(this,'{$vo.id}')" class="ml-5"
                            style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
                </tr>
                {/volist}
                {else /}
                <tr>
                    <td scope="col" colspan="4">没有数据</td>
                </tr>
                {/notempty}
                </tbody>
            </table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    /*管理员-编辑*/
    function edit(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url,
            area: ['800px', '600px']
        });
    }

    function del(obj, id) {
        layer.confirm('确认要删除吗？,同时aws上的文件也会被删除，不用担心垃圾过多！', function (index) {
            var postData = {};
            postData['id'] = id;
            var url = '/wavlink/files/download/del/' + id + '.html';
            //ajax 请求删除
            $.ajax({
                url: url,
                type: "post",
                data: postData,
                "success": function (result) {
                    console.log(result);
                    var msgData = JSON.parse(result);
                    if (msgData.status === true) {
                        $(obj).parents("tr").remove();
                        layer.msg(msgData.message, {icon: 1, time: 1000});
                    } else {
                        layer.msg(msgData.message, {icon: 5, time: 2000})
                    }
                }
            }, JSON);
        });
    }
</script>
{/block}